import global from "../../global";
import Player from "./player";
import Point_ts from "./point";

//转形的枚举
export enum Evolution {
    Ghost,      //幽灵
    Bone2,      //顽石第二天
    Bone1,      //顽石第一天
    Battery,    //炮台
    Kobold,     //地灵
    Null        //未转形
};

//符咒的枚举
export enum Spell{
    CSJJ,       //常胜将军
    PZJP,       //炮转狙炮
    GZCG,       //鬼转超鬼
    QXBS,       //潜行捕手
    SMWZ,       //沙漠王子
    CFPL,       //乘风破浪
    TLTX,       //桃李天下
    ELFS,       //恶灵附身
    SXMN,       //嗜血蛮牛 
    TYSD,       //天御圣灯
    WEDT,       //万厄毒体
    CPZJ,       //拆炮专家
    ZGDS,       //捉鬼大师
    XYSZ,       //骁勇善战
}

//buff的枚举
export enum Buff{
    fear,               //怯战
    gold,               //金身
    ice,                //冰冻
    virus,              //病毒
}

const {ccclass, property} = cc._decorator;

@ccclass
export default class Big extends cc.Component {

    @property(cc.SpriteFrame)
    Sf_normal:cc.SpriteFrame= null;         //大子原本图片
    @property(cc.SpriteFrame)
    Sf_hide:cc.SpriteFrame = null;          //大子潜行
    @property(cc.SpriteFrame)
    Sf_ghost:cc.SpriteFrame = null;         //幽灵图片
    @property(cc.SpriteFrame)
    Sf_bone:cc.SpriteFrame = null;          //顽石图片
    @property(cc.SpriteFrame)
    Sf_bone2:cc.SpriteFrame = null;          //顽石图片
    @property(cc.SpriteFrame)
    Sf_battery:cc.SpriteFrame = null;       //炮台图片
    @property(cc.SpriteFrame)
    Sf_kobold:cc.SpriteFrame = null;        //地灵图片

    @property(cc.Node)
    Node_tip:cc.Node = null;                 //点击提示

    @property(cc.Sprite)
    Sprite:cc.Sprite = null;                    //放大子图片的地方
   
    @property(cc.Node)
    Jian:cc.Node = null;        //键

    player:Player = null;       //玩家ts
    father:Big = null;          //父系大子

    @property(cc.Node)
    Buff:cc.Node = null;        //buff节点
    @property(cc.SpriteFrame)
    arr_buff_sf:cc.SpriteFrame[] = [];  //buff图片

    @property(cc.Node)
    Node_spell:cc.Node = null;          //总的符咒节点
    @property(cc.Node)
    arr_spell_node:Array<cc.Node> = [];      //四个符咒节点

    @property(cc.SpriteFrame)
    arr_spell_sf:cc.SpriteFrame[] = [];  //符咒图片

    /*********************************分割线************************************* */

    is_hide:boolean = false;        //潜行      潜行比较特别，不算buff
    is_clickable:boolean = true;    //是否可以点击,目前只有神兵天降

    evolution:Evolution = Evolution.Null;   //是否已经转形

    arr_spell:Set<Spell> = new Set<Spell>();      //全部符咒
    arr_buff:Set<Buff> = new Set<Buff>();         //全部buff

    onLoad(){
        this.Node_tip.active = false;
        this.Node_tip.setParent(global.mgr.Layer_tip);
        this.Buff.setParent(global.mgr.Layer_buff);
        this.Node_spell.setParent(global.mgr.Layer_spell);
        this.Jian.setParent(global.mgr.Layer_jian);
    }
    
    /**
     * 初始化 移动攻击等行动后也会执行初始化
     */
    init(point_ts:Point_ts){
        this.node.active = false;     //先隐藏，不然对方第一帧能看到
        this.Buff.setPosition(point_ts.node.position);
        this.Node_spell.setPosition(point_ts.node.position);
        this.Node_tip.setPosition(point_ts.node.position);
        this.showJian();
        if(this.evolution==Evolution.Null&&point_ts.real_type==3){  //判断是否是潜行
            this.is_hide = true;
        }else{
            this.is_hide = false;
        }
    }

    /**
     * 用于视野查看 flag = true 表示必须现形
     */
    show(flag:boolean = false){
        if(!flag&&this.is_hide&&!this.player.is_me){   //我是隐身的
            this.hide();
        }else{
            this.node.active = true;
            //潜行换图片
            if(this.is_hide){
                this.Sprite.spriteFrame = this.Sf_hide;
            }else{
                if(this.evolution == Evolution.Null){
                    this.Sprite.spriteFrame = this.Sf_normal;
                }else if(this.evolution == Evolution.Battery){
                    this.Sprite.spriteFrame = this.Sf_battery;
                }else if(this.evolution == Evolution.Ghost){
                    this.Sprite.spriteFrame = this.Sf_ghost;
                }else if(this.evolution == Evolution.Bone1){
                    this.Sprite.spriteFrame = this.Sf_bone;
                }else if(this.evolution == Evolution.Bone2){
                    this.Sprite.spriteFrame = this.Sf_bone2;
                }else if(this.evolution == Evolution.Kobold){
                    this.Sprite.spriteFrame = this.Sf_kobold;
                }
            }
            this.Buff.active = true;
            this.Node_spell.active = true;
            this.unschedule(this.display);
            this.display();
            this.schedule(this.display,1.1);
        }
    }
    hide(){
        this.node.active = false;
        this.Buff.active = false;
        this.Node_spell.active = false;
        this.Jian.active = false;
    }

    /**
     * 己方回合开始
     */
    oneDay(){
        this.arr_buff.delete(Buff.gold);
        this.is_canJP = true;
        this.is_clickable = true;
        //顽石破碎
        if(this.evolution!=Evolution.Null){         //大部分还是没转形的这样能少判断
            if(this.evolution==Evolution.Bone1){
                this.evolution = Evolution.Bone2;
                this.Sprite.spriteFrame = this.Sf_bone2;    //换成快要炸开的顽石图片
            }else if(this.evolution==Evolution.Bone2){      //两天到了，周围所有敌方大子都得死
                this.die();
                global.effect.playBoneBoom(this.node.parent.position);
                let index = this.node.parent.getComponent(Point_ts).index;
                let arr = global.getAround(index);
                arr.forEach(i=>{
                    let point_ts = global.mgr.map_point.get(i);
                    let big =point_ts.node.getChildByName("大子");
                    if(big){
                        let big_ts = big.getComponent(Big);
                        if(big_ts.player!=this.player){
                            big_ts.attacked();
                        }
                    }
                });
            }
        }
        //overover执行清理
        this.funOverWYCB = ()=>{};
    }

    /**
     * 己方回合结束
     */
    dayOver(){
        //buff清理
        this.arr_buff.delete(Buff.fear);
        this.arr_buff.delete(Buff.ice);
        //瘟疫传播
        if(this.arr_buff.has(Buff.virus)){
            //清空瘟疫，不管自己有没有被这一波毒死
            if(global.is_replay||this.node.parent.getComponent(Point_ts).is_view){
                global.effect.playWYCB(this.node.parent.position);
            }
            this.arr_buff.delete(Buff.virus);
            this.attacked();
            let index = this.node.parent.getComponent(Point_ts).index;
            let arr = global.getAround(index);
            arr.forEach(number=>{
                let point_ts = global.mgr.map_point.get(number);
                let big = point_ts.node.getChildByName("大子");
                if(big){
                    let big_ts = big.getComponent(Big);
                    if(big_ts.evolution==Evolution.Null&&big_ts.player.id==this.player.id){     //未转型 ，同一个人
                        big_ts.funOverWYCB = ()=>{big_ts.arr_buff.add(Buff.virus)};
                    }
                }
            });
        }
    }

    /**
     * 回合结束后，再结束一下
     */
    funOverWYCB:Function = ()=>{};          //瘟疫传播
    dayOverOver(){
        this.funOverWYCB();
    }

    /**
     * buff循环播放
     */
    index_buff = 0;     //顺序播放，表示当前播放到哪一个buff
    display(){
        //buff
        let arr = Array.from(this.arr_buff);
        if(arr.length==0){
            this.Buff.active = false;
        }else if(arr.length==1){
            this.Buff.active = true;
            this.Buff.scale = 1;
            this.Buff.getComponent(cc.Sprite).spriteFrame = this.arr_buff_sf[arr[0]];
        }else{
            this.Buff.active = true;
            this.Buff.scale = 0;
            if(arr.length==this.index_buff+1){
                this.index_buff = 0;
            }else{
                this.index_buff++;
            }
            this.Buff.getComponent(cc.Sprite).spriteFrame = this.arr_buff_sf[arr[this.index_buff]];
            cc.tween(this.Buff).to(.2,{scale:1}).delay(.7).to(.2,{scale:0}).start();
        }
        //spell
        if(this.arr_spell.size==0){
            this.Node_spell.active = false; //一个符咒也没有
            return;
        }
        this.Node_spell.active = true;
        this.arr_spell_node.forEach(node=>{
            node.active = false;
        });
        let index = 0
        this.arr_spell.forEach(spell=>{
            this.arr_spell_node[index].active = true;
            this.arr_spell_node[index].getComponent(cc.Sprite).spriteFrame = this.arr_spell_sf[spell];
            index++;
        });
    }

    /**
     * 获得视野
     */
    getViewArr(){
        let index = this.node.parent.getComponent(Point_ts).index;
        let arr = [];
        if(this.evolution==Evolution.Battery||this.evolution==Evolution.Ghost){
            arr = global.getAround2(index);
        }else if(this.evolution==Evolution.Bone1||this.evolution==Evolution.Bone2){
            arr = [];
        }else{
            arr = global.getAround(index);
        }
        arr.push(index);
        return arr;
    }

    /**
     * 获得移动范围
     */
    getMoveRangeArr(){
        let index = this.node.parent.getComponent(Point_ts).index;
        let arr = global.getAround(index);
        return arr;
    }

    /**
     * 获取幽灵移动范围
     */
    getGhostMoveRangeArr(){
        let index = this.node.parent.getComponent(Point_ts).index;
        let arr = global.getAround2(index);
        return arr;
    }

    /**
     * 获取炮台攻击范围
     */
    getBatteryAttackRangeArr(){
        let index = this.node.parent.getComponent(Point_ts).index;
        let arr = global.getAround2(index);
        return arr;
    }

    /**
     * 获取地灵改地形范围
     */
    getkoboldMagicRangeArr(){
        let index = this.node.parent.getComponent(Point_ts).index;
        let arr = global.getAround(index);
        return arr;
    }

    /**
     * 开始点击事件监听
     */
    openOn(){
        //冰冻的大子不能行动
        if(this.arr_buff.has(Buff.ice)&&this.evolution==Evolution.Null){
            return;
        }
        if(this.evolution==Evolution.Bone1||this.evolution==Evolution.Bone2){
            return;
        }
        if(this.evolution==Evolution.Battery&&this.arr_spell.has(Spell.PZJP)&&!this.is_canJP){
            return;
        }
        this.node.on(cc.Node.EventType.TOUCH_START,this.select,this);
        this.openEffect();
    }

    /**
     * 关闭点击事件监听
     */
    closeOn(){
        this.node.targetOff(this);
        this.closeEffect();
    }

    /**
     * 点击大子
     */
    select(){
        //关闭全部监听
        this.player.small.closeOn();
        this.player.arr_big.forEach(element=>{
            element.closeOn();
        });
        //把自己赋过去
        global.UI.big_ts = this;
        //判断自己是否已经转型
        if(this.evolution == Evolution.Null){       //未转形
            //开启防穿透
            global.UI.Layer_blockInput.active = true;
            //打开行动框
            let node = global.UI.BigAction;
            node.setPosition(this.node.parent.position);
            node.active = true;
            node.scale = 0;
            cc.tween(node).to(.2,{scale:1.5}).start();
        }else if(this.evolution == Evolution.Ghost){    //鬼移动
            this.ghostMove();
            this.node.on(cc.Node.EventType.TOUCH_START,this.cancel,this);
        }else if(this.evolution == Evolution.Kobold){   //灵开路
            this.koboldMagic();
            this.node.on(cc.Node.EventType.TOUCH_START,this.cancel,this);
        }else if(this.evolution == Evolution.Battery){  //炮攻击
            this.batteryAttack();
            this.node.on(cc.Node.EventType.TOUCH_START,this.cancel,this);
        }else if(this.evolution==Evolution.Bone1||this.evolution==Evolution.Bone2){
            //考虑以后会有可移动顽石
        }else{
            global.persist.tip("应该是不能点的");
            this.player.homing();
        }
    }

    /**
     * 取消全部该落点事件监听
     */
    offAll(){
        //取消事件监听
        this.node.targetOff(this);
        //关闭提示效果
        this.closeEffect();
    }
    
    /**
     * 开启点击提示特效 0：可以行动，1：可出出大，2：可以移动，3：可以攻击，4：可以施法
     */
    openEffect(type:number = 0){
        if(global.is_replay){
            return;
        }
        this.Node_tip.getComponent(cc.Sprite).spriteFrame = global.effect.Arr_sf_tip[type];
        this.Node_tip.active = true;
        this.Node_tip.opacity = 255;
        let action = cc.tween().to(1,{opacity:100}).delay(.2).to(1,{opacity:255});
        cc.tween(this.Node_tip).repeatForever(action).start();
    }
    /**
     * 关闭点击提示特效
     */
    closeEffect(){
        this.Node_tip.active = false;
        this.Node_tip.stopAllActions();
    }

    /**
     * 隐身暴露
     */
    expose(){
        this.is_hide = false;
        this.show();
    }

    /**
     * 怯战
     */
    fear(){
        this.arr_buff.add(Buff.fear)
    }

    /**
     * 键
     */
    showJian(){
        let end:cc.Node;
        if(this.father){
            end = this.father.node.parent;
        }else{
            end = this.player.small.node.parent;
        }
        let start = this.node.parent;
        let v2 = end.position.sub(start.position);
        this.Jian.width = v2.mag()-175;
        let angle = cc.v2(v2).signAngle(cc.v2(1,0));
		this.Jian.angle = cc.misc.radiansToDegrees(-angle);
        let cha_x = start.x-end.x;
        let cha_y = start.y-end.y;
        let xx = 0;
        let yy = 0;
        if(cha_x!=0&&cha_y!=0){
            xx = cha_x/(Math.abs(cha_x)+Math.abs(cha_y))*150;
            yy = cha_y/(Math.abs(cha_x)+Math.abs(cha_y))*150;
        }else if(cha_y!=0){
            this.Jian.width+=10;
            yy = cha_y/Math.abs(cha_y)*85;
        }else if(cha_x!=0){
            this.Jian.width+=10;
            xx = cha_x/Math.abs(cha_x)*85;
        }
        this.Jian.setPosition(start.x-xx,start.y-yy);
        //如果我是激活的，键会时时刷新，如果我被激活，直接关掉就好
        if(!this.node.active){
            this.Jian.active = false;
        }
    }

    /**
     * 开启取消行动监听
     */
    onCancel(){
        //自己开启监听，取消行动，其实就是全部归位
        this.node.on(cc.Node.EventType.TOUCH_START,this.cancel,this);
    }

    /**
     * 取消
     */
    cancel(){
        this.player.homing();
    }

    /**
     * 选择出大
     */
    selectBorn(){
        //周围point开启监听
        let arr = this.getMoveRangeArr();
        arr.forEach(index=>{
            global.mgr.map_point.get(index).onBigBorn();
        })
    }

    /**
     * 选择移动
     */
    selectMove(){
        //周围point开启监听
        let arr = this.getMoveRangeArr();
        let is_water = this.arr_spell.has(Spell.CFPL);          //乘风破浪移动
        arr.forEach(index=>{
            global.mgr.map_point.get(index).onBigMove(is_water);
        })
        //沙漠王子移动
        if(this.arr_spell.has(Spell.SMWZ)){
            global.mgr.map_point.forEach(point_ts=>{
                if(point_ts.real_type==4&&point_ts.is_view){
                    point_ts.onBigMove();
                }
            });
        }
    }

    /**
     * 选择攻击
     */
    selectAttack(){
        //周围point开启监听
        let arr = this.getMoveRangeArr();
        let is_water = this.arr_spell.has(Spell.CFPL);          //乘风破浪攻击
        arr.forEach(index=>{
            global.mgr.map_point.get(index).onBigAttack(is_water);
        })
    }

    /**
     * 转幽灵
     */
    toGhost(){
        let cost = 1;
        if(this.player.action<cost){
            this.fail(`需要${cost}点行动力`);
            return;
        }
        this.player.changeAction(-cost);
        this.is_hide = false;
        this.evolution = Evolution.Ghost;
        this.Sprite.spriteFrame = this.Sf_ghost;
        this.dieSon();
        this.evolutionOver();
        //播放音效
        if(global.is_replay||this.node.parent.getComponent(Point_ts).is_view){
            global.music_ts.playEffect("Audio_evolution");
        }
    }

    /**
     * 转顽石
     */
    toBone(){
        let cost = 1;
        if(this.player.action<cost){
            this.fail(`需要${cost}点行动力`);
            return;
        }
        this.player.changeAction(-cost);
        this.is_hide = false;
        this.evolution = Evolution.Bone1;
        this.Sprite.spriteFrame = this.Sf_bone;
        this.dieSon();
        this.evolutionOver();
        //播放音效
        if(global.is_replay||this.node.parent.getComponent(Point_ts).is_view){
            global.music_ts.playEffect("Audio_evolution");
        }
    }

    /**
     * 转炮台
     */
    toBattery(){
        let cost = 3;
        if(this.player.action<cost){
            this.fail(`需要${cost}点行动力`);
            return;
        }
        this.player.changeAction(-cost);
        this.is_hide = false;
        this.evolution = Evolution.Battery;
        this.Sprite.spriteFrame = this.Sf_battery;
        this.dieSon();
        this.evolutionOver();
        //播放音效
        if(global.is_replay||this.node.parent.getComponent(Point_ts).is_view){
            global.music_ts.playEffect("Audio_evolution");
        }
    }

    /**
     * 转地灵
     */
    toKobold(){
        let cost = 2;
        if(this.player.action<cost){
            this.fail(`需要${cost}点行动力`);
            return;
        }
        this.player.changeAction(-cost);
        this.is_hide = false;
        this.evolution = Evolution.Kobold;
        this.Sprite.spriteFrame = this.Sf_kobold;
        this.dieSon();
        this.evolutionOver();
        //播放音效
        if(global.is_replay||this.node.parent.getComponent(Point_ts).is_view){
            global.music_ts.playEffect("Audio_evolution");
        }
    }

    /**
     * 转型结束,清空全部状态，符咒保留
     */
    evolutionOver(){
        this.is_hide = false;
        this.arr_buff.clear();
    }

    /**
     * 幽灵移动
     */
    ghostMove(){
        //周围point开启监听
        let arr = this.getGhostMoveRangeArr();
        if(this.arr_spell.has(Spell.GZCG)){
            //超鬼移动
            arr.forEach(index=>{
                global.mgr.map_point.get(index).onCGMove();
            }) 
        }else{
            arr.forEach(index=>{
                global.mgr.map_point.get(index).onGhostMove();
            }) 
        }
    }

    /**
     * 地灵转地形
     */
    koboldMagic(){
        //周围point开启监听
        let arr = this.getkoboldMagicRangeArr();
        arr.forEach(index=>{
            global.mgr.map_point.get(index).onKoboldMagic();
        })
    }

    /**
     * 炮台攻击
     */
    is_canJP:boolean = true;        //每回合只能开一炮
    batteryAttack(){
        if(this.arr_spell.has(Spell.PZJP)){
            //狙炮
            let arr = global.mgr.getArrPointView();
            arr.forEach(point_ts=>{
                point_ts.onBatteryAim(); //选择瞄准目标
            });
        }else{
            //普通炮
            let arr = this.getBatteryAttackRangeArr();
            arr.forEach(index=>{
                global.mgr.map_point.get(index).onBatteryAttack();
            }) 
        }
    }

    /**
     * 操作提示
     */
    fail(s:string){
        if(this.player.is_me){
            global.persist.tip(s);
        }
    }

    /**
     * 死儿子
     */
    dieSon(){
        this.player.arr_big.forEach(big_ts=>{
            if(big_ts&&big_ts.father==this){
                big_ts.die();
            }
        });
    }

    /**
     * 死亡
     */
    die(is_fs:boolean=false){
        //开始死儿子
        this.dieSon();
        //然后死自己
        this.player.arr_big.delete(this);
        //记得删除键、buff、符咒、提示
        this.Jian.destroy();
        this.Buff.destroy();
        this.Node_spell.destroy();
        this.Node_tip.destroy();
        this.node.destroy();
        //播放音效
        //附身死亡不播放
        if(!is_fs){
            global.effect.playBigDie(this.node.parent.position,this.player.color);
        }
        
    }

    update(){
        //键要随时判断是否显示
        if(this.father){
            this.Jian.active = this.father.node.active;  
        }else{
            this.Jian.active = true;
        }
    }

    /**
     * 被攻击了 ,false 表示我没死
     */
    attacked(big:Big = null){
        if(this.evolution==Evolution.Bone1||this.evolution==Evolution.Bone2){
            return false;
        }
        this.expose();
        if(this.arr_buff.has(Buff.gold)){
            return false;
        }
        this.die();
        //进攻成功，这里执行效果  this表示被攻击的大子，big表示攻击者
        if(big){
            if(big.evolution==Evolution.Null&&big.arr_spell.has(Spell.CSJJ)){          //常胜将军
                big.arr_buff.add(Buff.gold);
            }
            if(big.arr_spell.has(Spell.SXMN)){          //嗜血蛮牛
                big.player.changeAction(2);
            }
        }
        return true;
    }

    /**
     * 常胜将军
     */
    oncsjj(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.csjj,this);
    }
    csjj(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.csjj);
        global.client.send({method:"skill",skill:"csjj",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }


    /**
     * 骁勇善战
     */
    onxysz(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.xysz,this);
    }
    xysz(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.xysz);
        global.client.send({method:"skill",skill:"xysz",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 炮转狙炮
     */
    onpzjp(){
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.pzjp,this);
    }
    pzjp(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.pzjp);
        global.client.send({method:"skill",skill:"pzjp",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 鬼转超鬼
     */
    ongzcg(){
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.gzcg,this);
    }
    gzcg(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.gzcg);
        global.client.send({method:"skill",skill:"gzcg",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 潜行捕手
     */
    onqxbs(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.qxbs,this);
    }
    qxbs(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.qxbs);
        global.client.send({method:"skill",skill:"qxbs",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 明魂搜跟
     */
    onmhsg(){
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.mhsg,this);
    }
    mhsg(){
        this.player.arr_big.forEach(big_ts=>{
            big_ts.show(true);
        });
        global.mgr.skill_ts.used();
        global.mgr.me_player.homing();
        global.client.send({method:"skillOnlyMe",skill:"mhsg",id:global.id});
    }

    /**
     * 属性置换
     */
    onsxzh(){
        if(this.evolution!=Evolution.Null || !this.is_clickable){     //转型过的不能置换
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.sxzh1,this);
    }
    sxzh1(){
        //我是要交换属性的大子之一
        global.mgrSkill.sxzh = this;
        global.mgr.clear();
        global.mgr.me_player.arr_big.forEach(big_ts=>{
            big_ts.onsxzh2();
        });
        this.offAll();  //不算自己
    }
    onsxzh2(){
        if(this.evolution!=Evolution.Null || !this.is_clickable){     //转型过的不能置换
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.sxzh2,this);
    }
    sxzh2(){
        //我是要交换属性的大子之二
        let index1 = global.mgrSkill.sxzh.node.parent.getComponent(Point_ts).index;
        let index2 = this.node.parent.getComponent(Point_ts).index;
        global.client.send({method:"skill",skill:"sxzh",index1,index2,id:global.id});
        global.mgr.skill_ts.used();
        global.mgr.clear();
    }

    /**
     * 绝命献祭
     */
    onjmxj(){
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.jmxj,this);
    }
    jmxj(){
        global.client.send({method:"skill",skill:"jmxj",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
        global.mgr.clear();
    }

    /**
     * 过度分裂
     */
    ongdfl(){
        if(this.evolution!=Evolution.Null){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.gdfl,this);
    }
    gdfl(){
        global.client.send({method:"skill",skill:"gdfl",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
        global.mgr.clear();
    }

     /**
     * 瘟疫传播
     */
    onwycb(){
        if(this.evolution!=Evolution.Null){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.wycb,this);
    }
    wycb(){
        global.mgr.pointOffAll();
        global.client.send({method:"skill",skill:"wycb",id:global.id,index:this.node.parent.getComponent(Point_ts).index});
        global.mgr.skill_ts.used();
    }

    /**
     * 沙漠王子
     */
    onsmwz(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.smwz,this);
    }
    smwz(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.smwz);
        global.client.send({method:"skill",skill:"smwz",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 乘风破浪
     */
    oncfpl(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.cfpl,this);
    }
    cfpl(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.cfpl);
        global.client.send({method:"skill",skill:"cfpl",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 桃李天下
     */
    ontltx(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.tltx,this);
    }
    tltx(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.tltx);
        global.client.send({method:"skill",skill:"tltx",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 恶灵附身
     */
    onelfs(){
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.elfs,this);
    }
    elfs(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.elfs);
        global.client.send({method:"skill",skill:"elfs",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 执行恶灵附身
     */
    doelfs(player:Player,father:Big){
        //原先的player里面清除自己,放到对方阵营
        this.player.arr_big.delete(this);
        player.arr_big.add(this);
        //子系也叛变
        this.elfsSon(player);
        //叛变完在切换father
        this.father = father;
        this.player = player;
        this.showJian();
        //记得变颜色
        this.Sprite.node.color = player.color;
        this.Jian.color = player.color;
    }
    elfsSon(player:Player){
        this.player.arr_big.forEach(big_ts=>{
            if(big_ts.father==this){
                big_ts.doelfs(player,this);
            }
        });
    }

    /**
     * 嗜血蛮牛
     */
    onsxmn(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.sxmn,this);
    }
    sxmn(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.sxmn);
        global.client.send({method:"skill",skill:"sxmn",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }
    
    /**
     * 绝育诅咒
     */
    onjyzz(){
        if(this.evolution!=Evolution.Null){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.jyzz,this);
    }
    jyzz(){
        global.mgr.pointOffAll();
        global.client.send({method:"skill",skill:"jyzz",id:global.id,index:this.node.parent.getComponent(Point_ts).index});
        global.mgr.skill_ts.used();
    }


    /**
     * 天御圣灯
     */
    ontysd(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.tysd,this);
    }
    tysd(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.tysd);
        global.client.send({method:"skill",skill:"tysd",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

    /**
     * 万厄毒体
     */
    onwedt(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.wedt,this);
    }
    wedt(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.wedt);
        global.client.send({method:"skill",skill:"wedt",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

     /**
     * 拆炮专家
     */
    oncpzj(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.cpzj,this);
    }
    cpzj(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.cpzj);
        global.client.send({method:"skill",skill:"cpzj",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

     /**
     * 捉鬼大师
     */
    onzgds(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        //身上符咒是4个的不能再施加
        if(this.arr_spell.size==4){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.zgds,this);
    }
    zgds(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.zgds);
        global.client.send({method:"skill",skill:"zgds",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }

     /**
     * 金身不灭
     */
    onjsbm(){
        //转型过的不能施加spell
        if(this.evolution!=Evolution.Null){
            return;
        }
        this.openEffect(4);
        this.node.on(cc.Node.EventType.TOUCH_START,this.jsbm,this);
    }
    jsbm(){
        this.node.off(cc.Node.EventType.TOUCH_START,this.jsbm);
        global.client.send({method:"skill",skill:"jsbm",index:this.node.parent.getComponent(Point_ts).index,id:global.id});
        global.mgr.skill_ts.used();
    }
}
